package DFS;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-03-19
 * Time:21:32
 * Text：230. 二叉搜索树中第K小的元素
 */
public class Text3 {
    int count=0,num=0;
    public void dfs(TreeNode root){
        if(root == null || count==0) return;
        dfs(root.left);
        count--;
        if(count == 0) num=root.val;

        if(count==0) return;

        dfs(root.right);
    }
    public int kthSmallest(TreeNode root, int k) {
        count=k;
        dfs(root);
        return num;
    }
}
